package com.company.test.countdownlathc;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatchDemo {

    public static void main(String[] args) throws Exception {
        CountDownLatch latch = new CountDownLatch(1000);
        ExecutorService pool = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 10; i++) {
            pool.execute(() -> {
                try {
                    Thread.sleep(new Random().nextInt(10) * 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("aaaa" + System.currentTimeMillis());
                latch.countDown();
            });
        }

        latch.await();
        System.out.println("end");
        pool.shutdown();

    }
}
